package com.yykt.myapp.service;

import com.yykt.myapp.entity.User;
import com.yykt.myapp.mapper.NewUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.time.Duration;

@Service
public class NewUserService {

    @Autowired
    NewUserMapper newUserMapper;

    public User getUserById(Long id) {
        User user = newUserMapper.getUserById(id);
        return user;
    }

    public void insertUser(User user) {
        newUserMapper.insertUser(user);
    }

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    public void setValue(String key, String value) {
        redisTemplate.opsForValue().set(key, value, Duration.ofMillis(5));
    }

    public Object getValue(String key) {
        return redisTemplate.opsForValue().get(key);
    }

}
